<%-- 
    Document   : wishlist-content
    Created on : May 20, 2011, 3:39:03 PM
    Author     : Joe
--%>

<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="pkg_productManagement.Product"%>
<%@page import="pkg_productManagement.ProductDatabaseFunctions"%>
<%@page import="pkg_group2_wishlist.WishLists"%>
<%@page import="pkg_group2_wishlist.WishListsService"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Vector"%>
<%@page import="java.text.*"%>
<%
    String id = (String) session.getAttribute("login");
    if (id != null) {
        String user = (String)session.getAttribute("user");
        Vector itemList = (Vector)session.getAttribute("items");
        out.println("<div class=\"page-title\">" + user + "'s Wishlist </div><br/>");
        int group = 5;
        int custID = Integer.parseInt(id.trim());
        WishListsService service = new WishListsService();
        WishLists port = service.getWishListsPort();
        // if customer not registered for wishlist create one
        try{
            port.addCustomer(group, custID);
            port.addList(group, custID, id);
        }
        catch (Exception e){
        }
        // if page access from add to wishlist request add item
        if(request.getParameter("product_id")!=null)
        {
            int productid = Integer.parseInt(request.getParameter("product_id"));
            try{
                port.addItem(group, custID, id, productid, "");
            }
             catch (Exception e){
        }
        }
        // show all items in list
        try{
            List<Integer> list = port.getListItems(group, custID, id);
            if (list.size()==1){
                out.println("You have 1 item in your wish list");
            }
            else {
                out.println("You have "+list.size()+ " items in your wish list");
            }
            ProductDatabaseFunctions pDF = new ProductDatabaseFunctions();
            Product product = null;
            for(int i=0; i<list.size(); i++)
            {
                int item = list.get(i);                
                product = pDF.getProductsByID(item);
                  
                
%>
        <div class="product">
        <table width="100%">
            <tbody>
            <th rowspan="3" width="80px"><img src="<% out.println(product.getImage());%>" /></th>
            <tr>
                <% NumberFormat formatter = new DecimalFormat("0.00"); String s = formatter.format(product.getPrice()); %>
                <%
                    String stringID = Integer.toString(item);
                %>
                <td class="cell-fill-blue"><a href="product.jsp?product_id=<%out.print(stringID);%>"><% out.println(product.getName());%></a></td>    
                <td class="cell-fill-blue"><% out.println("£"+s);%></td> 
            </tr>
            <th colspan="2"><% out.println(product.getDesc());%></th>
            </tbody>
        </table> 
    </div>
<%
            }
        }
             catch (Exception e){
        }
%>        

        
<%    }
    else {
 %>
    <div class="page-sub-title">Wishlist not available</div>
    <div class="intro">
        <p>You have to log into your account <a href="index.jsp">HERE</a> to view the wishlist. If you do not have an account register <a href="register.jsp">HERE.</a></p>
    </div>

 <%
   }
%>